#include "stdafx.h"
#include "sorting.h"
;using namespace std;


sorting::sorting()
{

	
}

sorting::~sorting()
{

}

int compare_ints(const void* a, const void* b)   // comparison function
{
    long unsigned int* arg1 = (long unsigned int*) a;
    long unsigned int* arg2 = (long unsigned int*) b;
    if( *arg1 < *arg2 ) return -1;
    else if( *arg1 == *arg2 ) return 0;
    else return 1;
}

void sorting::DoSort()
{
	Data_Manager DM;
	//TIGER_hash hash;//-----------------Here you can change hash!
	if(arr.size() > BubbleSortMaxSize)
	{
		QSort sort;
		DM.setStrategy(&sort);
		DM.Makesort(&arr);
	}
	else
	{
		Bubble sort;
		DM.setStrategy(&sort);
		DM.Makesort(&arr);
	}
		
}
void QSort::Tosort(std::vector <long unsigned int>* ndata)
{
	qsort(&(ndata->begin()), ndata->size(),sizeof(unsigned long int),compare_ints);
}

void Bubble::Tosort(std::vector <long unsigned int>* ndata)
{
	  long unsigned int sc = 0;
	  long unsigned int t;
	  long unsigned int i;
	  while(ndata->size() - sc >0)
	  {
		for(i = 1; i< ndata->size() - sc;i++)
		{
			if(*(ndata->begin()+i)<*(ndata->begin()+i-1))
			{
				t = *(ndata->begin()+i);
				*(ndata->begin()+i) = *(ndata->begin()+i-1);
				*(ndata->begin()+i-1) = t;
			}
		}
		sc++;
	  }
}
